import 'package:im_flutter_sdk_example/utils/time_util.dart';

class MomentModel {
  List<MomentItem> data = new List<MomentItem>();
  int total = 0;

  MomentModel({this.data, this.total});

  MomentModel.fromJson(Map<String, dynamic> json) {
    if (json['list'] != null) {
      data = new List<MomentItem>();
      json['list'].forEach((v) {
        data.add(new MomentItem.fromJson(v));
      });
    }
    total = json['total'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.data != null) {
      data['list'] = this.data.map((v) => v.toJson()).toList();
    }
    data['total'] = this.total;
    return data;
  }
}

class MomentItem {
  List<String> pictures;
  int likes;
  String sId;
  String publishUserId;
  String groupId;
  String publishUserName;
  String content;
  String createdTime;
  String updatedTime;

  MomentItem(
      {this.pictures,
      this.likes,
      this.sId,
      this.publishUserId,
      this.groupId,
      this.publishUserName,
      this.content,
      this.createdTime,
      this.updatedTime});

  MomentItem.fromJson(Map<String, dynamic> json) {
    pictures = json['pictures'].cast<String>();
    likes = json['likes'];
    sId = json['_id'];
    publishUserId = json['publish_user_id'];
    groupId = json['group_id'];
    publishUserName = json['publish_user_name'];
    content = json['content'];
    createdTime = TimeUtil.getFormatTime(json['created_time']);
    updatedTime = json['updated_time'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['pictures'] = this.pictures;
    data['likes'] = this.likes;
    data['_id'] = this.sId;
    data['publish_user_id'] = this.publishUserId;
    data['group_id'] = this.groupId;
    data['publish_user_name'] = this.publishUserName;
    data['content'] = this.content;
    data['created_time'] = this.createdTime;
    data['updated_time'] = this.updatedTime;
    return data;
  }
}
